const Generator = require('yeoman-generator')

module.exports = class extends Generator {

  // foo () {
  //   this.log('我的第一个生成器!')
  // }
  constructor (args, opts) {
    super(args, opts)


  }

  // 1.询问,获取信息
  prompting () {
    return this.prompt([
      {
        type: 'input',
        name: 'appname',
        message: '请输入项目的名称:',
        default: this.appname
      },
      {
        type: 'input',
        name: 'username',
        message: '请输入您的姓名:',
        default: '无名'
      }
    ])
    .then(answers => {
      // this.log(answers)
      this.answers = answers
    })
  }
 

  // 2.生成预定义的项目结构
  writing () {
    let srcDir = this.sourceRoot()
    let destDir = this.destinationRoot()
    this.fs.copyTpl(srcDir, destDir, this.answers)
  }
 

  // 3.安装依赖
  install () {
    this.env.options.nodePackageManager = 'npm'
  }

  end () {
    this.log('项目创建成功!')
  }
}